package com.godyao.mall.user.boot.service.impl;

import com.godyao.mall.user.boot.repository.SysRoleRepository;
import com.godyao.mall.user.boot.repository.SysUserRepository;
import com.godyao.mall.user.boot.service.ISysUserService;
import com.godyao.mall.user.common.model.SysRole;
import com.godyao.mall.user.common.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author godyao
 * @date 2022/4/1
 */
@Service
public class SysUserServiceImpl implements ISysUserService {
    @Autowired
    private SysUserRepository sysUserRepository;

    @Autowired
    private SysRoleRepository sysRoleRepository;

    @Override
    public SysUser getUserByUsername(String username) {
        return sysUserRepository.findByUsernameAndStatus(username, 1).get();
    }

    @Override
    public List<SysRole> getRolesByUserId(Long userId) {
        return sysRoleRepository.getRolesByUserId(userId);
    }

    @Override
    public SysUser getByUserId(String userId) {
        return sysUserRepository.findByUserIdAndStatus(userId, 1).get();
    }

    @Override
    public List<SysUser> listByUserId(List<String> userIds) {
        return sysUserRepository.findByUserIdInAndStatus(userIds, 1);
    }
}
